package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@Api(tags = "分类相关接口")
@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping
    @ApiOperation("菜品分类")
    public Result addCategory(@RequestBody CategoryDTO category) {
        System.out.println(category);
        categoryService.addCategory(category);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页显示菜品分类")
    public Result getAllCategory(CategoryPageQueryDTO categoryPageQueryDTO) {

        return Result.success(categoryService.getAllCategory(categoryPageQueryDTO));
    }

    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteCategory(Integer id) {
        categoryService.delete(id);
        return Result.success();

    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用，禁用菜品")
    public Result updateCategoryStatus(@PathVariable("status") Integer status, Long id) {
        categoryService.update(id, status);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改分类")
    public Result updateCategory(@RequestBody CategoryDTO category) {
        categoryService.updateClass(category);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据类型查询")
    public Result getAllCategoryByClass(Integer type) {
        return Result.success(categoryService.getCategroyByClass(type));

    }

}
